var Utils_Base = new Class({
	initialize: function(){
	},
	rand: function(){
        var now = new Date().getTime(); return now + "_" + now % 23;
	},
	login: function(tipType){
		var nowUrl = window.location.href;
		var url = '/login_portal/?to=' + String.encode(nowUrl);
		if($chk2(tipType)) url = url + '&tip=' + tipType;
		url.toURI().go();
		if(Env.Browser.name == 'MSIE') window.event.returnValue = false;
	},
	getHoverTips: function(item){
		var vid = parseInt(item.get('vid'));
		var div_id = vid + '_detail'; if($(div_id)) return;
		var div = new Element('div',{id:div_id, 'class':'detailBox', style:'display:none;'});
		document.body.appendChild(div);
		new echoAjax({url:"/video/" + vid + "/little/hovertip/?" + this.rand(),method:'get',type:'html',
			onSuccess: function(tree,elements,html,js){
				div.innerHTML = html;
				div.stick({relativeTo:item,position:'right',edge:'left',allowOutWindow:true});
			},
			onFailure: function(){}
		}).fire();
	},
	addHoverTips: function(){
		var lnks = $$('.poster');
		var myTimer; var self = this;
		for(var i=0,len=lnks.length;i<len;i++){
			lnks[i].addEvent('mouseenter',function(){
				myTimer = function() {
					var div = $(this.get("vid")+"_detail");
					if(div) div.stick({relativeTo:this,position:'right',edge:'left',allowOutWindow:true});
					else{ self.getHoverTips(this); }
				}.delay(500,this);
			});
			lnks[i].addEvent('mouseleave',function(){
				var div = $(this.get("vid")+"_detail");
				if(div) div.hide();
				$clear(myTimer);
			});
		}
	}
});
var Utils = new Utils_Base();
var SImgUploader = new Class({
	_options: {}, _direction:'bottom',_cssClass:'simgUploader', _container:null,
	_title:'', _titlePrefix:'上传图片', _formAction:'.',  _tips:'请上传不大于100K的图片文件(最好jpg)',
	_initImg:'/static/images/pic_preview.jpg',
	initialize: function(options){
		if(options.formAction) this._formAction = options.formAction;
		if(options.initImg) this._initImg = options.initImg;
		this._options = options;
		if(options.title) this._title = this._titlePrefix + ' - ' + options.title;
		else this._title = this._titlePrefix;
		this.createBox();
	},
	createBox: function(){
		var action = Base64.encode(this._formAction);
		var img = Base64.encode(this._initImg);
		var url = String.format('/simgup/?action={0}&initImg={1}',action,img);
		var _iframe = new Element('iframe',{width:380,height:200,frameborder:0,scrolling:'no'});
		this._container = new MsgBox({title:this._title,minWidth:400,buttons:[],onClose:function(){window.location.reload();}});
		this._container.appendElement(_iframe);
		_iframe.src = url;
	}
});

